package com.chinaisafe.user.vo.response;

import cn.hutool.core.collection.CollectionUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * LoginTenantTreeVO
 * Description：
 *
 * @author xuefu.shu
 * @date 2024-07-15 9:42
 */
@Data
@Schema(name = "LoginTenantTreeVO", description = "登录租户树")
public class LoginTenantTreeVO {

    @Schema(description = "租户id")
    private Long id;

    @Schema(description = "租户父id")
    private Long parentId;

    @Schema(description = "租户名称")
    private String name;

    @Schema(description = "租户别名")
    private String alias;

    @Schema(description = "租户编码")
    private String code;

    @Schema(description = "是否可选")
    private Boolean checkable;

    @Schema(description = "子节点")
    private List<LoginTenantTreeVO> children;


    /**
     * 设置子节点
     *
     * @param children 子节点
     * @return boolean
     */
    public boolean setChildrenBy(LoginTenantTreeVO children) {
        if (CollectionUtil.isEmpty(this.children)) {
            this.children = new ArrayList<>();
            this.children.add(children);
        } else {
            for (LoginTenantTreeVO child : this.children) {
                if (child.getId().equals(children.getId())) {
                    return false;
                }
            }
            this.children.add(children);
        }
        return true;
    }
}
